Use dfClient.pkg
Use DataDict.pkg
Use Windows.pkg

Use ROSTER.DD

DEFERRED_VIEW Activate_oLearnLocalSave FOR ;
;
Object oLearnLocalSave is a dbView

    Property String psMBLabel "Rosters"

    Set Border_Style to Border_Thick
    Set Label to "Learn Local Save"
    Set Location to 2 2
    Set Size to 159 392

    Object oIntoText is a Textbox
        Set Label to "Demonstates Datadictionary saves.  Also augments Request_Validate so that player cannot weight over 300 pounds."
        Set Location to 9 13
        Set Size to 10 369
        Set TypeFace to "MS Sans Serif"
    End_Object    // oIntoText


    Object oRoster_DD is a Roster_DataDictionary

        Function Request_Validate Returns Boolean
            Boolean bFail
            String sMsg sFirstName sLastName
            Number nWeight
            Integer iNum

            Forward Get Request_Validate to bFail
            If (not(bFail)) Begin
                Get Field_Current_Value Field Roster.Weight to nWeight
                If (nWeight > 300) Begin
                    Get Field_Current_Value Field Roster.First_name  to sFirstName
                    Get Field_Current_Value Field Roster.Last_name  to sLastName
                    Get Field_Current_Value Field Roster.Num to iNum
                    Move ( (Trim(sFirstName)) * (Trim(sLastname)) * "(" + (string(iNum)) + ") " ) to sMsg
                    Append sMsg "\nweighs more than maximum allowable wieght."
                    Append sMsg "\n(" (string(nWeight)) " is over 300.)"
                    Send Info_Box sMsg (psMBLabel(self))
                    Move true to bFail
                End
            End
            Function_Return bFail
        End_Function

    End_Object 

    Set Main_DD to oRoster_DD
    Set Server to oRoster_DD

    Object oAdd_grp is a Group
        Set Size to 101 345
        Set Location to 26 20
        Set Label to "Add New Player"
        Object oJerseyNumAdd is a Form
            Set Label to "Jersey Num"
            Set Size to 13 60
            Set Location to 20 15
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oFirstNameAdd is a Form
            Set Label to "First Name"
            Set Size to 13 60
            Set Location to 20 100
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oLastNameAdd is a Form
            Set Label to "Last Name"
            Set Size to 13 60
            Set Location to 21 183
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oPosAdd is a Form
            Set Label to "Position"
            Set Size to 13 60
            Set Location to 47 17
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oHeightFeetAdd is a Form
            Set Label to "Height Feet"
            Set Size to 13 60
            Set Location to 47 98
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oHeightInchAdd is a Form
            Set Label to "Height Inch"
            Set Size to 13 60
            Set Location to 47 185
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oWeight is a Form
            Set Label to "Weight"
            Set Size to 13 60
            Set Location to 47 267
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to jMode_Top
        End_Object

        Object oAdd_btn is a Button
            Set Label to "Add Player"
            Set Size to 14 78
            Set Location to 69 195

            Procedure OnClick
                Integer iNum 
                Number nHeightFeet nHeightInch nWeight
                String sLastName sFirstName sPos

                Get value of oJerseyNumAdd to iNum
                Get value of oLastNameAdd to sLastName
                Get value of oFirstNameAdd to sFirstName
                Get value of oPosAdd to sPos
                Get value of oHeightFeetAdd to nHeightFeet
                Get value of oHeightInchAdd to nHeightInch
                Get value of oWeight to nWeight
                               
                Send AddPlayer iNum sLastName sFirstName sPos nHeightFeet nHeightInch nWeight                
            End_Procedure

        End_Object 

    End_Object
    
    Procedure AddPlayer Integer iNum String sLastName String sFirstName String sPos ;
                        Number nHeightFeet Number nHeightInch Number nWEight
        Boolean bFail
        
        Send Clear of oRoster_DD                       // will clear global buffer as well.
        Move iNum to Roster.Num
        Find EQ Roster by Index.1
        If (not(Found)) Begin
            Set Field_Changed_Value of oRoster_DD Field Roster.Num to iNum

            Set Field_Changed_Value of oRoster_DD Field Roster.Last_name to sLastName
            Set Field_Changed_Value of oRoster_DD Field Roster.First_Name to sFirstName
            Set Field_Changed_Value of oRoster_DD Field Roster.Pos to sPos
            Set Field_Changed_Value of oRoster_DD Field Roster.Height_feet to nHeightFeet
            Set Field_Changed_Value of oRoster_DD Field Roster.Height_inch to nHeightInch
            Set Field_Changed_Value of oRoster_DD Field Roster.Weight to nWeight
            Get Request_Validate of oRoster_DD to bFail
            If (not(bFail)) Send Request_Save of oRoster_DD
        End
         Else Send Info_Box ("Player " + (String(iNum)) + " already exists.")        
    End_Procedure

Cd_End_Object

